// service/applicant/applicant.js
import http from "../../utils/http"
import util from "../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    state: 0,
    showPopup:false,
    list:[],
    finish: false,
    loading: false,
    page: 1,
    id: '',
    percent: ''
  },
  refuse(e){
    let id = e.currentTarget.dataset.info.id
    http.get('shop/joinshoplist',{
      type: 'check',
      id: id,
      state: -1,
    }).then(res => {
      util.toast(res.msg)
      this.reload()
    })
  },
  consent(e){
    let id = e.currentTarget.dataset.info.id
    this.setData({
      showPopup: true,
      id: id
    })
  },
  onClose() {
    this.setData({ showPopup: false });
  },
  setPercent(e){
    this.setData({
      percent: e.detail.value
    })
  },
  agree(){
    if (this.data.percent.trim() === '') return util.toast('请输入订单抽成')
    if (this.data.percent < 0 || this.data.percent > 100) return util.toast('请输入正确的订单抽成')
    http.get('shop/joinshoplist',{
      type: 'check',
      id: this.data.id,
      state: 1,
      percent: this.data.percent
    }).then(res => {
      util.toast(res.msg)
      this.reload()
      this.setData({
        showPopup: false
      })
    })
  },
  call(e){
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.mobile
    })
  },
  onChange(e){
    this.setData({
      state: Number(e.detail.name)
    })
    this.reload()
  },
  reload(){
    this.setData({
      list: [],
      page: 1,
      finish: false
    })
    this.getList()
  },
  more(){
    this.setData({
      page: ++this.data.page
    })
    this.getList()
  },
  getList(){
    if(this.data.finish){
      return 
    }
    if(this.data.loading){
      return 
    }
    this.setData({
      loading: true
    })
    http.get('shop/joinshoplist', {
      page: this.data.page,
      state: this.data.state
    }).then(res => {
      if(res.data.length === 0){
        this.setData({
          finish: true
        })
      }
      let arr = this.data.list.concat(res.data)
      this.setData({
        list: arr
      })
      
    }).finally(res => {
      this.setData({
        loading: false
      })
    })
  },
  onClick(event) {
 
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.reload()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})